<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>车主信息</title>
	<link th:include="common/header::copy"/>
<script type="text/javascript">
	
	function searchUser(){
		$("#dg").datagrid('load',{
			"vidcard":$("#S_vidcard").val(),
            "phone":$("#s_phone").val(),
            "idcard":$("#s_idcard").val(),
            "lname":$("#s_lname").val(),
		});
	}

    function saveusersearchUser(){
        $("#dg").datagrid('load',{
            "username":$("#s_userName").val()
        });
    }
	
	function resetValue(){
        $("#lid").val("");
        $("#lname").textbox('clear');
        $("#idcard").textbox('clear');
        $("#phone").textbox('clear');
        $("#cidcard").textbox('clear');
        $("#paymentTypeName").textbox('clear');
        $("#account").textbox('clear');
        $("#depositBank").textbox('clear');
        $("#paymentType").textbox('clear');
	}
	
	function closeUserDialog(){
		$("#dlg").dialog("close");
		resetValue();
	}

    function saveUser(){
        $("#fm").form("submit",{
            url:'/veh/leader/save',
            method:'post',
            onSubmit:function(){
                return $(this).form("validate");
            },
            success:function(result){
                debugger;
                var result=eval('('+result+')');
                if(result.success){
                    $.messager.show({
                        title: '系统提示',
                        msg: '保存成功！',
                        timeout: 3000,
                        showType: 'show'
                    });
                   /* $.messager.alert("系统提示","保存成功！");*/
                    resetValue();
                    $("#dlg").dialog("close");
                    $("#dg").datagrid("reload");
                }else{
					$.messager.show({
						title:'系统提示',
						msg:result.info,
						timeout:1000,
						showType:'show'
					});
                }
            }
        });

    }
	
	function openUserAddDialog(){
		$("#lid").removeAttr("readonly");
		$("#dlg").dialog("open").dialog("setTitle","添加车主信息");
	}

	function openUserModifyDialog(index){
			$("#dg").datagrid('selectRow',index);
			var row =$("#dg").datagrid('getSelected');
			if(row) {
				$("#dlg").dialog("open").dialog("setTitle", "修改车主信息");
				$("#fm").form("load", row);
				$("#id").attr("readonly", "readonly");
			}
	}

    function sdeleteUser(id){
        $.messager.confirm("系统提示","您确定要删除这条数据吗?",function(r){
            if(r){
                $.post("/veh/leader/delete",{id:id},function(result){
                    if(result.success){
                        $.messager.show({
                            title:'系统提示',
                            msg:'数据已成功删除！',
                            timeout:3000,
                            showType:'show'
                        });
                        // $.messager.alert("系统提示","数据已成功删除！");
                        $("#dg").datagrid("reload");
                    }else{
                        $.messager.alert("系统提示",result.Info);
                    }
                },"json");
            }
        });
    }




    function formatop(val,row,index) {
        return '<a href="#" onclick="openUserModifyDialog('+index+')">修改</a>&nbsp;&nbsp;' +
           	 '<a href="#" onclick="sdeleteUser('+row.id+')">删除</a>&nbsp;&nbsp;';
    }


	
</script>
</head>
<body style="margin: 1px">
	<table id="dg" title="车主信息" class="easyui-datagrid"
	fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
	url="/veh/leader/list" fit="true" toolbar="#tb" method="Post" striped="true">
		<thead>
            <th field="id" width="20" align="center" hidden="true">编号</th>
			<th field="lname" width="20" align="center">车主姓名</th>
			<th field="idcard" width="50" align="center">车主身份证</th>
			<th field="phone" width="40" align="center">车主手机</th>
			<th field="payment_type" width="50" align="center">支付方式</th>
			<th field="account" width="20" align="center">个人账户</th>
            <th field="op" width="20" align="center" formatter="formatop">操作</th>
        </thead>
	</table>
	
	<div id="tb">
        <div shiro:hasPermission="veh:leader:list" style="display: inline-block;float: right;">
            车主手机：<input type="text" id="s_phone" size="20" onkeydown="if(event.keyCode==13) searchUser()"/>
            身&nbsp;份&nbsp;证：<input type="text" id="s_idcard" size="20" onkeydown="if(event.keyCode==13) searchUser()"/>
            车主姓名：<input type="text" id="s_lname" size="20" onkeydown="if(event.keyCode==13) searchUser()"/>
			<a href="javascript:searchUser()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
		</div>

        <div style="display: inline-block;">
            <a shiro:hasPermission="veh:leader:save" href="javascript:openUserAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
			<a href="javascript:uploadidalogonline(2)" class="easyui-linkbutton" plain="true">导入</a>
			<a href="javascript:"  class="easyui-linkbutton" data-options="plain:true" onclick="$('#dg').datagrid('toExcel','lea.xls');">导出</a>
        </div>

	</div>
	
	
	<div id="dlg" class="easyui-dialog" style="width: 900px;height: 500px;padding: 10px 20px"
	closed="true" buttons="#dlg-buttons" data-options="onClose:function(){resetValue()}">
		<form id="fm" method="post">
            <input type="hidden" id="id" name="id">
			<table cellspacing="8px">
                <h2 style="border-bottom-color: #99cdff">车主信息</h2>
                <div style="margin-bottom:10px">
                    <input name="lname" id="lname" class="easyui-textbox" required="true" label="车主姓名:" style="width:300px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
                <div style="margin-bottom:10px">
                    <input name="phone" id="phone" class="easyui-textbox" required="true" label="车主手机:" style="width:300px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
                <div style="margin-bottom:10px">
                    <input name="idcard" id="idcard" class="easyui-textbox" required="true" label="车主身份证:" style="width:300px">&nbsp;&nbsp;&nbsp;
                </div>
				<div style="margin-bottom:10px">

					<input class="easyui-combobox"
						   label="支付方式:"
						   style="width:300px"
						   name="paymentType"
						   data-options="
					url:'/veh/payment-type/getAll',
					method:'get',
					valueField:'paymentTypeId',
					textField:'paymentTypeName',
					panelHeight:'auto' ">

				</div>
				<div style="margin-bottom:10px">
					<input name="account" id="account" class="easyui-textbox" required="true" label="个人账户:" style="width:300px">&nbsp;&nbsp;&nbsp;
				</div>
				<div style="margin-bottom:10px">
					<input name="depositBank" id="depositBank" class="easyui-textbox" required="true" label="开户银行:" style="width:300px">&nbsp;&nbsp;&nbsp;
				</div>
			</table>
		</form>
	</div>
	
	<div id="dlg-buttons">
		<a href="javascript:saveUser()" class="easyui-linkbutton" iconCls="icon-ok" >保存</a>
		<a href="javascript:closeUserDialog()" class="easyui-linkbutton" iconCls="icon-cancel" >关闭</a>
	</div>


	<div id="uploadonlineinfo" class="easyui-dialog" style="width:380px;padding:10px 40px" closed="true">
		<form id="fam" method="post" enctype="multipart/form-data">
			<input type="file" id="file" name="file">
			<input type="hidden" id="flag" name="flag">
		</form>

		<div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
			<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)"
			   onclick="uploadonline();" style="width:80px">上传</a>
		</div>
	</div>
	<script type="text/javascript">

		function uploadidalogonline(flag) {
			$('#uploadonlineinfo').dialog('open').dialog('setTitle', '文件上传');
			$("#flag").val(flag);

		}

		function uploadonline() {
			var file = $("#file")[0].files[0];
			var flag = $("#flag").val();
			var url;
			if (file.name == "") {
				alert("请先选择文件");
				return false;
			}
			if (flag == 1) {
				url = "/image/upload";
				if (!file.name.match(/.jpg|.jpeg|.gif|.png|.bmp/i)) {

					alert("文件格式错误");
					return false;
				}
			} else {
				url = "/veh/leader/excelImport";
				if (!file.name.match(/.xls|.xlsx/i)) {
					alert("文件格式错误");
					return false;
				}
			}
			var form = new FormData();
			form.append("file", file);
			var picget = "/image/show?fileName=" + file.name;
			$.ajax({
				url: url,
				type: "post",
				data: form,
				processData: false,
				contentType: false,
				success: function (data) {
					$('#uploadonlineinfo').window('close');
					if (flag == 1) {

					}
					console.log(data);
				},
				error: function (e) {
					console.log(e);
				}
			});
		}
	</script>
</body>
</html>